package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Name  string  `gorm:"type:varchar(30);comment:商品名称"`
	Price float64 `gorm:"type:decimal(10,2);comment:商品价格"`
	Num   int     `gorm:"type:int;comment:商品库存"`
}

func (Goods) TableName() string {
	return "goods"
}

func (g *Goods) Find(id int64) (result Goods, err error) {
	err = DB.Where("id=?", id).Find(&result).Error
	if err != nil {
		return Goods{}, err
	}
	return result, nil
}

func (g *Goods) Finds() (result []Goods, err error) {
	err = DB.Find(&result).Error
	if err != nil {
		return nil, err
	}
	return result, nil
}
